import { EventTarget } from "cc";

export enum GameDataMgrEventEnum{
    COIN = 'coin',// 金币 
}
/**金币刷新类型 用这个判断是哪里导致金币的刷新*/
export enum GoldTypeRefresh{
    recharge = "recharge",//充值
    game  = "game",//普通游戏功能
    bet = "bet",//下注
}
/**储存用户游戏中的数据*/
export class GameDataMgr {
    private static _instance:GameDataMgr;
    private _eventTarget: EventTarget = new EventTarget();
    private  _coin:number//用户当前金币余额
    public static get instance(): GameDataMgr {
        if (this._instance == null) {
            this._instance = new GameDataMgr();
        }
        return this._instance;
    }
    public on(type: string, callback: any, thisArg?: any, once?: boolean): void {
        this._eventTarget.on(type, callback, thisArg, once);
    }
    public off(type: string, callback: any, thisArg?: any): void {
        this._eventTarget.off(type, callback, thisArg);
    }
    public offAll(thisArg: any):void{
        this._eventTarget.removeAll(thisArg);
    }
    public setCoin(coin:number,type:GoldTypeRefresh=GoldTypeRefresh.game):void{
        this.dispatchEvent(GameDataMgrEventEnum.COIN,type);
    }
    public getCoin():number{
        return this._coin;
    }
    private dispatchEvent(type: string,arg0?: any): void {
        this._eventTarget.emit(type,arg0);
    }

}   